#include "common.hpp"

#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <cstring>
#include <fcntl.h>
#include <cstdio>
#include <unistd.h>

int main()
{
    int fd = open(pathname.c_str(), O_RDONLY, 0666);
    if(fd < 0)
    {
        ERR_EXIT("open");
    }
    std::cout << "open success" << std::endl;

    // 拿到文件描述符准备读文件
    char buffer[1024];
    ssize_t n = read(fd, buffer, sizeof buffer - 1);
    if(n < 0)
    {
        ERR_EXIT("read");
    }
    std::cout << "read success:" << buffer << std::endl;
    buffer[n] = 0;

    close(fd);

    return 0;
}